package com.ygqh.common.okhttp.exception;


import com.ygqh.common.utils.StringUtil;

public class OkHttp3Exception extends Exception {

    private static final long serialVersionUID = -2588299589058935464L;

    private String errorCode;

    private String errorMsg;

    public OkHttp3Exception() {
    }

    public OkHttp3Exception(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public OkHttp3Exception(Exception e) {
        this.errorCode = "500";
        this.errorMsg = e.getMessage();
    }

    public OkHttp3Exception(String errorMsg) {
        this.errorCode = "500";
        this.errorMsg = errorMsg;
    }

    public OkHttp3Exception(Throwable e) {
        super(e);
    }

    public OkHttp3Exception(String message, Throwable cause) {
        super(message, cause);
    }

    public String getErrorCode() {
        return errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    @Override
    public String getMessage() {
        StringBuilder buf = new StringBuilder();
        if (StringUtil.isNotBlank(errorCode)) {
            buf.append(errorCode);
        }
        if (StringUtil.isNotBlank(errorMsg)) {
            buf.append(" ").append(errorMsg);
        }
        if (buf.length() == 0) {
            return super.getMessage();
        }
        return buf.toString();
    }

}
